/** @file
 *  Library to manage Agilent Infiniium Oscilloscope.
 *  @example test_osc.cpp
 */
#include "socket_client.hpp"
#include <stdint.h>

#ifndef __OSC_CONTROL__

#ifndef DOXYGEN
#define __OSC_CONTROL__
#endif

/** Max possible size of an integer = 10^N */
const int max_integer_len = 8;

/** A class to manage Agilent Infiniium Oscilloscope */
class osc_control:private tcp_client
{

  /** Buffer for storing integer in getInteger() */
  char buffer[max_integer_len];

  /** Get returned integer from the oscilloscope by running a command.
   *  @param command SCPI command ending in '\\n'
   *  @return integer returned from the oscilloscope.
   */
  int getInteger (char command[]);

  /** Get returned string from the oscilloscope by running a command.
   *  @param command SCPI command ending in '\\n'
   *  @param count expected length of the string, excluding '\\0'
   *  @retval buffer string returned from the oscilloscope, terminated with '\\0'
   */
  void getString (char command[], char buffer[], unsigned long count);

  /** Get binary array from the oscilloscope by running a command.
   *  @param command SCPI command ending in '\\n'
   *  @param count expected number of bytes of the binary array.
   *  @retval IntArray byte array returned from the oscilloscope, terminated with '\\0'
   */
  void getBinaryArray (char command[], char *IntArray, unsigned long count);

public:

  /** Constructor. */
    osc_control ();

  /** Destructor */
   ~osc_control ();

  /** Test whether the oscilloscope is ready.
   *  @return 1 if ready; 0 otherwise.
   */
  bool testReady ();

  /** Identify the oscilloscope.
   *  This is to check whether the oscilloscope is compatible with this interface.
   *  @return 1 if device ID match; 0 othervise.
   */
  bool identify ();

  /** Preset oscolloscope for data acquistion.
   *  @return 1 if preset without error; 0 othervise.
   */
  bool preset ();

  /** Get number of points in the acquired trace.
   *  @return number of data points in the active trace.
   */
  int number_of_points ();

  /** Get trace data in 8-bit format
   *  @param count number of datapoints
   *  @retval data data in int8_t format
   */
  void getTrace8 (int8_t data[], unsigned count);
};

#endif
